using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_DanhSachDonHang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    #region"Load data"
    private void LoadData()
    {
        pager.PageSize = 5;
        Criteria c = new Criteria();
        if (txt_TenKH.Text != "")
        {

            c.add(Condition.AND + " tbKhachHang.MaKH=tbDonHang.MaKH and ", tbKhachHangColumns.HoTen, Condition.LIKE,
                txt_TenKH.Text);
        }

        int total = 0;
        tbDonHangCollection donHangCollection =
            tbDonHangBUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize,
            tbDonHangColumns.MaDH.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = donHangCollection;
        Repeater1.DataBind();

        pager.ItemCount = total;

    }
    #endregion
 
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        LoadData();

    }
    protected void lbt_Xoa_Click(object sender, EventArgs e)
    {
        //for (int i = 0; i < Repeater1.Items.Count; i++)
        //{
        //    CheckBox cb_Xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
        //    if (cb_Xoa.Checked == true)
        //    {
        //        HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
        //        int id = int.Parse(hf_id.Value);
        //        tbDonHangBUS.UpdateTrangThai(id);
        //    }
        //}
        //Response.Redirect(Request.RawUrl);
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
           e.Item.ItemType == ListItemType.Item)
        {
            tbDonHang donHang = (tbDonHang)e.Item.DataItem;
            tbKhachHang khachHang = tbKhachHangBUS.GetByID(donHang.MaKH);
            Literal lit_tenKH = (Literal)e.Item.FindControl("lit_tenKH");
            lit_tenKH.Text = khachHang.HoTen;
            CheckBox cb_Xoa = (CheckBox)e.Item.FindControl("cb_Xoa");
         
             
        }
    }
}
